function bciTrain(trainOnRuns,option)
% bciTrain(trainOnRuns)
% trainOnRuns is optional (vector of run numbers), default is all acquired
% runs in global GLOBALtrainDat
% required toolboxes: fieldtrip,spider,chronux
% use_spider;
global GLOBALbci;
global GLOBALtrainDat;
global GLOBALtrainSet;

if exist('svm','file')~=2,
    error('Check toolbox pathes');
end

if nargin==0,
    trainOnRuns=false(1,length(GLOBALtrainDat));
    for k=1:length(GLOBALtrainDat),
        trainOnRuns(k)=~isempty(GLOBALtrainDat{k});
    end
end

[GLOBALbci,Train]=bciGetTrainDat(GLOBALbci,GLOBALtrainDat{trainOnRuns});
if nargin==2,
    if strfind(option,'reverse'), % reverse the labels
        Train.label(Train.label==GLOBALbci.leftEvent)=-1;
        Train.label(Train.label==GLOBALbci.rightEvent)=GLOBALbci.leftEvent;
        Train.label(Train.label==-1)=GLOBALbci.rightEvent;
        % add load classifier data?
    else
        error('option unknown or file does not exist');
    end
end
GLOBALbci=bciTrainClassifier(GLOBALbci,Train);

if GLOBALbci.param.retrainClassifier, % needed for updating the classifier
    GLOBALtrainSet = Train;
end